import { Controller, Get, Post, Body, Patch, Param, Delete, Query, UseFilters, UseGuards } from '@nestjs/common';
import { LinkService } from './link.service';
import { CreateLinkDto } from './dto/create-link.dto';
import { UpdateLinkDto } from './dto/update-link.dto';
import { GetLinkDto } from './dto/get-link.dto';
import { TypeormFilter } from 'src/common/filters/typeorm.filter';
import { JwtGuard } from 'src/common/guards/jwt.guard';
import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { LinkResultVo } from './vo/link.result.vo';

@Controller('link')
@ApiTags('友情链接')
@UseFilters(new TypeormFilter())
export class LinkController {
  constructor(private readonly linkService: LinkService) {}

  @Post()
  @ApiOperation({summary:'新增友情链接'})
  @ApiResponse({type:Number})
  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  create(@Body() createLinkDto: CreateLinkDto) {
    return this.linkService.create(createLinkDto);
  }

  @Get()
  @ApiOperation({summary:'友情链接列表'})
  @ApiResponse({type:LinkResultVo})
  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  findAll(@Query() query:GetLinkDto) {
    return this.linkService.findAll(query,true);
  }

  @Get('user')
  @ApiOperation({summary:'友情链接列表（博客端）'})
  @ApiResponse({type:LinkResultVo})
  findAllUser(@Query() query:GetLinkDto) {
    return this.linkService.findAll(query,false);
  }

  @Get(':id')
  @ApiOperation({summary:'友情链接详情'})
  @ApiResponse({type:LinkResultVo})
  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  findOne(@Param('id') id: string) {
    return this.linkService.findOne(+id);
  }

  @Patch(':id')
  @ApiOperation({summary:'友情链接修改'})
  @ApiResponse({type:null})
  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  update(@Param('id') id: string, @Body() updateLinkDto: UpdateLinkDto) {
    return this.linkService.update(+id, updateLinkDto);
  }

  @Delete(':id')
  @ApiOperation({summary:'友情链接删除'})
  @ApiResponse({type:null})
  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  remove(@Param('id') id: string) {
    return this.linkService.remove(+id);
  }
}
